<?php if(count($eventAssets)){?>
<?php
	$i = 0;
	$firstItem = null;
	$itemToShow = null;
	$itemIndex = 0;
	$itemsIndex = array();
	if(!isset($assetToShow))
	{
		$assetToShow = null;
	}
	foreach($eventAssets as $eventAsset){
		if($i == 0)
		{
			$firstItem = $eventAsset;
		}
		if($assetToShow && $eventAsset['EventAsset']['id'] == $assetToShow)
		{
			$itemIndex = $i;
			$itemToShow = $eventAsset;
		}
		$itemsIndex[$i] = $eventAsset['EventAsset']['id'];
		$i++;
	}
	if(!$itemToShow)
	{
		$itemToShow = $firstItem;
		$itemIndex = 0;
	}
?>
<?php
	$prevId = $nextId = null;
	$prevId = @$itemsIndex[$itemIndex - 1];
	$nextId = @$itemsIndex[$itemIndex + 1];
?>
<div class="gallery_layout">
	<div class="paginate gallery_paginate" style="">
	<?php
	$nextText = __("Next >>");
	$prevText = __("<< Prev");
	?>
	<?php
	if(!is_null($prevId))
	{
		echo $html->link($prevText,am($this->params['pass'],am($this->params['named'],array("show"=>$prevId))));
	}else
	{
		echo $prevText;
	}
	?>
		<strong> <?php echo sprintf(__("%d  of %d"),$itemIndex+1,count($itemsIndex))?>
		</strong>
		<?php
		if(!is_null($nextId))
		{
			echo $html->link($nextText,am($this->params['pass'],am($this->params['named'],array("show"=>$nextId))));
		}else
		{
			echo $nextText;
		}
		?>
	</div>
	<div class="selected_image_display">
		<div class="selected_image" style="" id="selected_image">
		<?php echo $html->link($asset->preview($itemToShow['EventAsset'], array('class'=>'', 'id'=>"main_asset_image",'thumb'=>array('width'=>400,'height'=>400))),am($this->params['pass'],am($this->params['named'],array("show"=>$nextId))),array("escape"=>false));?>
		</div>

	</div>

	<div class="uploader_info">
	<?php if(isset($eventGallery)){?>

		<div style="margin-bottom: 1px; margin-top: 1px;">
		<?php
		if(isset($itemToShow['EventAsset']['poster']))
		{
			echo $html->link($html->image($itemToShow['EventAsset']['poster']['avatar'],array('class'=>"profile_pic",'alt'=>sprintf(__("%s profile"),$itemToShow['EventAsset']['poster']['username']),'thumb'=>array('crop'=>true,'width'=>40,'height'=>40))),$itemToShow['EventAsset']['poster']['profile_url'],array("escape"=>false));
		}
		?>
		</div>
		<div>
		<?php echo __("Uploaded By")?>
		<?php
		if(isset($itemToShow['EventAsset']['poster']))
		{
			echo $html->link($itemToShow['EventAsset']['poster']['display_name'],$itemToShow['EventAsset']['poster']['profile_url']);
		}
		else
		{
			echo "Admin";
		}
		?>
		</div>
		<?php }else{ ?>
		<?php echo __("Uploaded In")?>
		<div style="margin-bottom: 1px; margin-top: 1px;">
		<?php echo $html->link($html->image($itemToShow['Event']['image'],array('class'=>"profile_pic",'alt'=>$itemToShow['Event']['title'],'thumb'=>array('crop'=>true,'width'=>40,'height'=>40))),$itemToShow['Event']['viewUrl'],array("escape"=>false));?>
		</div>
		<div>
		<?php echo $html->link($itemToShow['Event']['title'],$itemToShow['Event']['viewUrl']);?>
		</div>
		<?php } ?>
		<div>
		<?php echo $time->timeAgoInWords($itemToShow['EventAsset']['created'],array('shortString'=>true));?>
		<?php if(isset($itemToShow['EventAsset']['poster']) && $itemToShow['EventAsset']['poster']['id'] == $session->read("Auth.User.id") && cr("EventConfig.allow_asset_edit")){?>
		<?php echo " | ".$html->link(__("Delete"),array("action"=>"delete",$itemToShow['EventAsset']['id']),array(),__("Are you sure you want to delete this image?"));?>
		<?php } ?>
		<?php //echo $report->link("EventAsset",$assetData['EventAsset']['id'],array('title'=>"Report"))?>
		</div>
	</div>
</div>
<div style="padding-top: 10px; padding-bottom: 40px;">
<?php
$i = 0;
$columns = 3;
foreach($eventAssets as $eventAsset)
{
	$eventAssetInfo = $eventAsset;
	$eventAsset = $eventAsset['EventAsset'];

	if(strlen($eventAsset['name']) < 1)
	continue;
	//if($i%$columns==0) echo "<div class='clr' ></div>"; ?>

	<div class="galleryImage"
		style="float: left; padding-right: 10px; padding-top: 40px;">
		<?php
		$url = am($this->params['pass'],$this->params['named'],array("show"=>$eventAsset['id']));
		$imageHtml = $asset->preview($eventAsset, array('thumb'=>array('height'=>76,'width'=>100,'crop'=>true)));
		echo $html->link($imageHtml,$url,array('escape'=>false)); ?>
		<div style="padding-top: 5px">
		<?php if(isset($eventGallery)){?>
		<?php echo __("By")?>
		<?php
		if(isset($eventAsset['poster'])){
			echo $html->link($eventAsset['poster']['display_name'],$eventAsset['poster']['profile_url']);
		}
		else
		{
			echo "Admin";
		}
		?>
		<?php }else{ ?>
		<?php echo __("In")?>
		<?php echo $html->link($eventAssetInfo['Event']['title'],$eventAssetInfo['Event']['viewUrl']);?>
		<?php } ?>
		</div>
	</div>
	<span class="clear"></span>

	<?php $i++;
}
?>
	<div class="clear"></div>
</div>
<div>
<?php
$paginator->options(array('url'=>$this->getPagingUrl()));
echo $paginator->numbers()?>
</div>
<script>
  $(document).ready(function() {
    var fn = function(){
    var height = $('#main_asset_image').height();
    if(height == 0)
    {
      return;
    }
    height = 450 -height;
    if(height > 1)
     {
       height = height/2;
       $('#selected_image').css("padding-top",height+'px');
     }
    }
    $('#main_asset_image').load(fn);
    setTimeout(fn,3000);
  })
</script>
<?php }else{?>
<h4>
<?php echo __("No image has been uploaded yet for this event yet.")?>
</h4>
<?php } ?>
